package main

import "fmt"

// 统计边界数最大的位置

func leastBricks(wall [][]int) int {
	// wall 数组不能直接用
	m := make(map[int]int)

	for _, row := range wall {
		curLen := 0
		// 注意边缘不算，所以len(row)-1
		for i := 0; i < len(row)-1; i++ {
			curLen += row[i]
			m[curLen]++
		}
	}
	fmt.Println(m)
	// 判断边界
	maxBorderCnt := 0
	for _, v := range m {
		maxBorderCnt = max(maxBorderCnt, v)
	}
	return len(wall) - maxBorderCnt
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	wall := [][]int{
		{1, 2, 2, 1}, {3, 1, 2}, {1, 3, 2}, {2, 4}, {3, 1, 2}, {1, 3, 1, 1},
	}
	res := leastBricks(wall)
	fmt.Println(res)
}
